<template>
  <div class="myadd">
    <van-nav-bar
      title="我的收货地址"
      left-text="返回"
      right-text="地址"
      left-arrow
      @click-left="onClickLeft"
    />
    <main>
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        @edit="onEdit"
        @add="onAdd"
      />
    </main>
  </div>
</template>

<script>
import { Toast } from "vant";
import { address_list } from "../../api/index2";

export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [
        /*  {
          id: "1",
          name: "张三",
          tel: "13000000000",
          address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
          isDefault: true,
        },
        */
      ],
    };
  },
  methods: {
    onClickLeft() {
        this.$router.back()
    },

    onAdd() {
        this.$router.push("/NewAddress")
    },
    onEdit(item, index) {
      // console.log(item.name);
      console.log(item.addressid);
      this.$router.push({path:"/changeAddress",
      query:{
        "name":item.name,
        "tel":item.tel,
        "addressDetail":item.addressDetail,
        "addressid":item.id
      }})
    },
  },
  mounted(){
    // userid 用户id 必须传
    address_list({
        userid:(localStorage.getItem("userid"))/1
    }).then((res)=>{
        if(res.data.code == 200){
            // console.log(" this.list ",this.list.length );
            this.list = res.data.list
            this.list.forEach(item=>{
                item.tel = item.phone
            })
        }
    })
  }
};
</script>

<style scoped>
.myadd {
  height: 100%;
}
</style>